<?php
header("Content-Type: text/html; charset=UTF-8");
session_start();
include_once( 'config.php' );
include_once( 'weibooauth.php' ); 

$this_page = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];

if (array_key_exists('keys',$_SESSION) && array_key_exists('oauth_token',$_SESSION['keys']) && array_key_exists('oauth_token_secret',$_SESSION['keys'])
    && array_key_exists('oauth_verifier',$_GET) && array_key_exists('oauth_token',$_GET)){
    
    $o = new WeiboOAuth( $Wb_AppKey , $Wb_AppSecret , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret']  );
    $last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;
    session_destroy();

    echo '新浪微博登录数据获取程序 im007boy@gmail.com 提供<br />';
    echo '<a href="http://www.neverbest.com" target="_blank">http://www.neverbest.com</a><br />';
    echo '<pre style="border:1px solid #000;padding:5px;background-color:#E5ECF9;border:1px solid #3366CC;">';
    echo '/*以下信息复制到rss.php的相应位置*/'."\n";
    echo '/*登录信息设置开始*/'."\n";
    echo '/*严禁泄露登录信息 否则别人可以登录你的帐号为所欲为*/'."\n";
    echo '$Oauth_Token = \'' . $last_key['oauth_token'] . '\';'."\n"; 
    echo '$Oauth_Token_Secret = \'' . $last_key['oauth_token_secret'] . '\';'."\n"; 
    echo '/*登录设置结束*/'."\n";
    echo '</pre>';
    echo "<a href=\"$this_page\">重新获取</a>";
}else{
    if (array_key_exists('oauth_verifier',$_REQUEST)){
        session_destroy();
        Header('Location:'.$this_page);
    }    
    $o = new WeiboOAuth( $Wb_AppKey , $Wb_AppSecret );

    $keys = $o->getRequestToken();
    $aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , $this_page);

    $_SESSION['keys'] = $keys;
    echo '新浪微博登录数据获取程序 im007boy@gmail.com 提供<br />';
    echo '<a href="http://www.neverbest.com" target="_blank">http://www.neverbest.com<br />';
    echo "<a href=\"$aurl\">获取登录信息</a>";

}



?>